package com.jbl.ma.controller;


import com.jbl.commonutils.R;
import com.jbl.ma.entity.TalkRecord;
import com.jbl.ma.service.TalkRecordService;
import com.jbl.ma.vo.TalkRecordVo;
import com.jbl.ma.vo.TalkVo;
import com.jbl.te.service.TeacherService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author jbl
 * @since 2020-12-11
 */

@CrossOrigin
@RestController
@RequestMapping("/ma/talk-record")
public class TalkRecordController {
    @Autowired
    private TalkRecordService talkRecordService;

    @PostMapping("/list")
    @ApiOperation("获取消息列表")
    public R list(Boolean isTeacher,String teacherNumber) {
        List<TalkRecordVo> collect = talkRecordService.getRecord(isTeacher,teacherNumber);
        return R.ok().data("talkRecord", collect);
    }

    @PostMapping("/chat/{teacherNumber}")
    @ApiOperation("获取聊天记录")
    public R chat(@PathVariable("teacherNumber") String teacherNumber) {
        List<TalkVo> collect = talkRecordService.getChat(teacherNumber);
        return R.ok().data("msgList", collect);
    }

    @PostMapping("/send")
    @ApiOperation("发送消息")
    public R sendMsg(@RequestBody TalkRecord talkRecord) {
        talkRecordService.save(talkRecord);
        return R.ok().data("gmtCreate", talkRecord.getGmtCreate());
    }

}
